home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / cpu / h6280 / h6280ops.h < prev    next >
Text File  |  2000-05-04  |  39KB  |  1,116 lines

  1. /*****************************************************************************
  2.  
  3.     h6280ops.h - Addressing modes and opcode macros for the Hu6820 cpu
  4.  
  5.     Copyright (c) 1999 Bryan McPhail, mish@tendril.co.uk
  6.  
  7.     This source code is based (with permission!) on the 6502 emulator by
  8.     Juergen Buchmueller.  It is released as part of the Mame emulator project.
  9.     Let me know if you intend to use this code in any other project.
  10.  
  11. ******************************************************************************/
  12.  
  13. /* 6280 flags */
  14. #define _fC 0x01
  15. #define _fZ 0x02
  16. #define _fI 0x04
  17. #define _fD 0x08
  18. #define _fB 0x10
  19. #define _fT 0x20
  20. #define _fV 0x40
  21. #define _fN 0x80
  22.  
  23. /* some shortcuts for improved readability */
  24. #define A    h6280.a
  25. #define X    h6280.x
  26. #define Y    h6280.y
  27. #define P    h6280.p
  28. #define S    h6280.sp.b.l
  29.  
  30. #if LAZY_FLAGS
  31.  
  32. #define NZ    h6280.NZ
  33. #define SET_NZ(n)                \
  34.     P &= ~_fT;                    \
  35.     NZ = ((n & _fN) << 8) | n
  36.  
  37. #else
  38.  
  39. #define SET_NZ(n)                \
  40.     P = (P & ~(_fN|_fT|_fZ)) |    \
  41.         (n & _fN) |             \
  42.         ((n == 0) ? _fZ : 0)
  43.  
  44. #endif
  45.  
  46. #define EAL h6280.ea.b.l
  47. #define EAH h6280.ea.b.h
  48. #define EAW h6280.ea.w.l
  49. #define EAD h6280.ea.d
  50.  
  51. #define ZPL h6280.zp.b.l
  52. #define ZPH h6280.zp.b.h
  53. #define ZPW h6280.zp.w.l
  54. #define ZPD h6280.zp.d
  55.  
  56. #define PCL h6280.pc.b.l
  57. #define PCH h6280.pc.b.h
  58. #define PCW h6280.pc.w.l
  59. #define PCD h6280.pc.d
  60.  
  61. #define DO_INTERRUPT(vector)                                    \
  62. {                                                                \
  63.     h6280.extra_cycles += 7;    /* 7 cycles for an int */        \
  64.     PUSH(PCH);                                                    \
  65.     PUSH(PCL);                                                    \
  66.     COMPOSE_P(0,_fB);                                            \
  67.     PUSH(P);                                                    \
  68.     P = (P & ~_fD) | _fI;    /* knock out D and set I flag */    \
  69.     PCL = RDMEM(vector);                                        \
  70.     PCH = RDMEM((vector+1));                                    \
  71. }
  72.  
  73. #define CHECK_IRQ_LINES                                         \
  74.     if( !(P & _fI) )                                            \
  75.     {                                                            \
  76.         if ( h6280.irq_state[0] != CLEAR_LINE &&                \
  77.              !(h6280.irq_mask & 0x2) )                            \
  78.         {                                                        \
  79.             DO_INTERRUPT(H6280_IRQ1_VEC);                        \
  80.             (*h6280.irq_callback)(0);                            \
  81.         }                                                        \
  82.         else                                                    \
  83.         if ( h6280.irq_state[1] != CLEAR_LINE &&                \
  84.              !(h6280.irq_mask & 0x1) )                            \
  85.         {                                                        \
  86.             DO_INTERRUPT(H6280_IRQ2_VEC);                        \
  87.             (*h6280.irq_callback)(1);                            \
  88.         }                                                       \
  89.         else                                                    \
  90.         if ( h6280.irq_state[2] != CLEAR_LINE &&                \
  91.              !(h6280.irq_mask & 0x4) )                            \
  92.         {                                                        \
  93.             h6280.irq_state[2] = CLEAR_LINE;                    \
  94.              DO_INTERRUPT(H6280_TIMER_VEC);                        \
  95.        }                                                           \
  96.     }
  97.  
  98. /***************************************************************
  99.  *  RDMEM   read memory
  100.  ***************************************************************/
  101. #define RDMEM(addr)                                             \
  102.     cpu_readmem21( (h6280.mmr[(addr)>>13] << 13) | ((addr)&0x1fff))
  103.  
  104. /***************************************************************
  105.  *  WRMEM   write memory
  106.  ***************************************************************/
  107. #define WRMEM(addr,data)                                        \
  108.     cpu_writemem21( (h6280.mmr[(addr)>>13] << 13) | ((addr)&0x1fff),data);
  109.  
  110. /***************************************************************
  111.  *  RDMEMZ   read memory - zero page
  112.  ***************************************************************/
  113. #define RDMEMZ(addr)                                             \
  114.     cpu_readmem21( (h6280.mmr[1] << 13) | ((addr)&0x1fff));
  115.  
  116. /***************************************************************
  117.  *  WRMEMZ   write memory - zero page
  118.  ***************************************************************/
  119. #define WRMEMZ(addr,data)                                         \
  120.     cpu_writemem21( (h6280.mmr[1] << 13) | ((addr)&0x1fff),data);
  121.  
  122. /***************************************************************
  123.  *  RDMEMW   read word from memory
  124.  ***************************************************************/
  125. #define RDMEMW(addr)                                            \
  126.     cpu_readmem21( (h6280.mmr[(addr)  >>13] << 13) | ((addr  )&0x1fff)) \
  127. | ( cpu_readmem21( (h6280.mmr[(addr+1)>>13] << 13) | ((addr+1)&0x1fff)) << 8 )
  128.  
  129. /***************************************************************
  130.  *  RDZPWORD    read a word from a zero page address
  131.  ***************************************************************/
  132. #define RDZPWORD(addr)                                            \
  133.     ((addr&0xff)==0xff) ?                                        \
  134.         cpu_readmem21( (h6280.mmr[1] << 13) | ((addr)&0x1fff))                \
  135.         +(cpu_readmem21( (h6280.mmr[1] << 13) | ((addr-0xff)&0x1fff))<<8) : \
  136.         cpu_readmem21( (h6280.mmr[1] << 13) | ((addr)&0x1fff))                \
  137.         +(cpu_readmem21( (h6280.mmr[1] << 13) | ((addr+1)&0x1fff))<<8)
  138.  
  139.  
  140. /***************************************************************
  141.  * push a register onto the stack
  142.  ***************************************************************/
  143. #define PUSH(Rg) cpu_writemem21( (h6280.mmr[1] << 13) | h6280.sp.d,Rg); S--
  144.  
  145. /***************************************************************
  146.  * pull a register from the stack
  147.  ***************************************************************/
  148. #define PULL(Rg) S++; Rg = cpu_readmem21( (h6280.mmr[1] << 13) | h6280.sp.d)
  149.  
  150. /***************************************************************
  151.  *  RDOP    read an opcode
  152.  ***************************************************************/
  153. #define RDOP()                                                    \
  154.     cpu_readop((h6280.mmr[PCW>>13] << 13) | (PCW&0x1fff))
  155.  
  156. /***************************************************************
  157.  *  RDOPARG read an opcode argument
  158.  ***************************************************************/
  159. #define RDOPARG()                                                \
  160.     cpu_readop_arg((h6280.mmr[PCW>>13] << 13) | (PCW&0x1fff))
  161.  
  162. /***************************************************************
  163.  *    BRA  branch relative
  164.  ***************************************************************/
  165. #define BRA(cond)                                                \
  166.     if (cond)                                                    \
  167.     {                                                            \
  168.         h6280_ICount -= 4;                                        \
  169.         tmp = RDOPARG();                                        \
  170.         PCW++;                                                    \
  171.         EAW = PCW + (signed char)tmp;                            \
  172.         PCD = EAD;                                                \
  173.     }                                                            \
  174.     else                                                        \
  175.     {                                                            \
  176.         PCW++;                                                    \
  177.         h6280_ICount -= 2;                                        \
  178.     }
  179.  
  180. /***************************************************************
  181.  *
  182.  * Helper macros to build the effective address
  183.  *
  184.  ***************************************************************/
  185.  
  186. /***************************************************************
  187.  *  EA = zero page address
  188.  ***************************************************************/
  189. #define EA_ZPG                                                    \
  190.     ZPL = RDOPARG();                                            \
  191.     PCW++;                                                        \
  192.     EAD = ZPD
  193.  
  194. /***************************************************************
  195.  *  EA = zero page address + X
  196.  ***************************************************************/
  197. #define EA_ZPX                                                    \
  198.     ZPL = RDOPARG() + X;                                        \
  199.     PCW++;                                                        \
  200.     EAD = ZPD
  201.  
  202. /***************************************************************
  203.  *  EA = zero page address + Y
  204.  ***************************************************************/
  205. #define EA_ZPY                                                    \
  206.     ZPL = RDOPARG() + Y;                                        \
  207.     PCW++;                                                        \
  208.     EAD = ZPD
  209.  
  210. /***************************************************************
  211.  *  EA = absolute address
  212.  ***************************************************************/
  213. #define EA_ABS                                                    \
  214.     EAL = RDOPARG();                                            \
  215.     PCW++;                                                        \
  216.     EAH = RDOPARG();                                            \
  217.     PCW++
  218.  
  219. /***************************************************************
  220.  *  EA = absolute address + X
  221.  ***************************************************************/
  222. #define EA_ABX                                                  \
  223.     EA_ABS;                                                     \
  224.     EAW += X
  225.  
  226. /***************************************************************
  227.  *    EA = absolute address + Y
  228.  ***************************************************************/
  229. #define EA_ABY                                                    \
  230.     EA_ABS;                                                     \
  231.     EAW += Y
  232.  
  233. /***************************************************************
  234.  *    EA = zero page indirect (65c02 pre indexed w/o X)
  235.  ***************************************************************/
  236. #define EA_ZPI                                                    \
  237.     ZPL = RDOPARG();                                            \
  238.     PCW++;                                                        \
  239.     EAD = RDZPWORD(ZPD)
  240.  
  241. /***************************************************************
  242.  *  EA = zero page + X indirect (pre indexed)
  243.  ***************************************************************/
  244. #define EA_IDX                                                    \
  245.     ZPL = RDOPARG() + X;                                        \
  246.     PCW++;                                                        \
  247.     EAD = RDZPWORD(ZPD);
  248.  
  249. /***************************************************************
  250.  *  EA = zero page indirect + Y (post indexed)
  251.  ***************************************************************/
  252. #define EA_IDY                                                    \
  253.     ZPL = RDOPARG();                                            \
  254.     PCW++;                                                        \
  255.     EAD = RDZPWORD(ZPD);                                        \
  256.     EAW += Y
  257.  
  258. /***************************************************************
  259.  *    EA = indirect (only used by JMP)
  260.  ***************************************************************/
  261. #define EA_IND                                                    \
  262.     EA_ABS;                                                     \
  263.     tmp = RDMEM(EAD);                                            \
  264.     EAD++;                                                         \
  265.     EAH = RDMEM(EAD);                                            \
  266.     EAL = tmp
  267.  
  268. /***************************************************************
  269.  *    EA = indirect plus x (only used by JMP)
  270.  ***************************************************************/
  271. #define EA_IAX                                                  \
  272.     EA_ABS;                                                        \
  273.     EAD+=X;                                                        \
  274.     tmp = RDMEM(EAD);                                            \
  275.     EAD++;                                                          \
  276.     EAH = RDMEM(EAD);                                            \
  277.     EAL = tmp
  278.  
  279. /* read a value into tmp */
  280. #define RD_IMM    tmp = RDOPARG(); PCW++
  281. #define RD_IMM2    tmp2 = RDOPARG(); PCW++
  282. #define RD_ACC    tmp = A
  283. #define RD_ZPG    EA_ZPG; tmp = RDMEMZ(EAD)
  284. #define RD_ZPX    EA_ZPX; tmp = RDMEMZ(EAD)
  285. #define RD_ZPY    EA_ZPY; tmp = RDMEMZ(EAD)
  286. #define RD_ABS    EA_ABS; tmp = RDMEM(EAD)
  287. #define RD_ABX    EA_ABX; tmp = RDMEM(EAD)
  288. #define RD_ABY    EA_ABY; tmp = RDMEM(EAD)
  289. #define RD_ZPI    EA_ZPI; tmp = RDMEM(EAD)
  290. #define RD_IDX    EA_IDX; tmp = RDMEM(EAD)
  291. #define RD_IDY    EA_IDY; tmp = RDMEM(EAD)
  292.  
  293. /* write a value from tmp */
  294. #define WR_ZPG    EA_ZPG; WRMEMZ(EAD, tmp)
  295. #define WR_ZPX    EA_ZPX; WRMEMZ(EAD, tmp)
  296. #define WR_ZPY    EA_ZPY; WRMEMZ(EAD, tmp)
  297. #define WR_ABS    EA_ABS; WRMEM(EAD, tmp)
  298. #define WR_ABX    EA_ABX; WRMEM(EAD, tmp)
  299. #define WR_ABY    EA_ABY; WRMEM(EAD, tmp)
  300. #define WR_ZPI    EA_ZPI; WRMEM(EAD, tmp)
  301. #define WR_IDX    EA_IDX; WRMEM(EAD, tmp)
  302. #define WR_IDY    EA_IDY; WRMEM(EAD, tmp)
  303.  
  304. /* write back a value from tmp to the last EA */
  305. #define WB_ACC    A = (UINT8)tmp;
  306. #define WB_EA    WRMEM(EAD, tmp)
  307. #define WB_EAZ    WRMEMZ(EAD, tmp)
  308.  
  309. /***************************************************************
  310.  *
  311.  * Macros to emulate the 6280 opcodes
  312.  *
  313.  ***************************************************************/
  314.  
  315. /***************************************************************
  316.  * compose the real flag register by
  317.  * including N and Z and set any
  318.  * SET and clear any CLR bits also
  319.  ***************************************************************/
  320. #if LAZY_FLAGS
  321.  
  322. #define COMPOSE_P(SET,CLR)                                        \
  323.     P = (P & ~(_fN | _fZ | CLR)) |                                \
  324.         (NZ >> 8) |                                             \
  325.         ((NZ & 0xff) ? 0 : _fZ) |                                \
  326.         SET
  327.  
  328. #else
  329.  
  330. #define COMPOSE_P(SET,CLR)                                        \
  331.     P = (P & ~CLR) | SET
  332.  
  333. #endif
  334.  
  335. /* 6280 ********************************************************
  336.  *    ADC Add with carry
  337.  ***************************************************************/
  338. #define ADC                                                     \
  339.     if (P & _fD)                                                \
  340.     {                                                            \
  341.     int c = (P & _fC);                                            \
  342.     int lo = (A & 0x0f) + (tmp & 0x0f) + c;                     \
  343.     int hi = (A & 0xf0) + (tmp & 0xf0);                         \
  344.         P &= ~(_fV | _fC);                                        \
  345.         if (lo > 0x09)                                            \
  346.         {                                                        \
  347.             hi += 0x10;                                         \
  348.             lo += 0x06;                                         \
  349.         }                                                        \
  350.         if (~(A^tmp) & (A^hi) & _fN)                            \
  351.             P |= _fV;                                            \
  352.         if (hi > 0x90)                                            \
  353.             hi += 0x60;                                         \
  354.         if (hi & 0xff00)                                        \
  355.             P |= _fC;                                            \
  356.         A = (lo & 0x0f) + (hi & 0xf0);                            \
  357.     }                                                            \
  358.     else                                                        \
  359.     {                                                            \
  360.     int c = (P & _fC);                                            \
  361.     int sum = A + tmp + c;                                        \
  362.         P &= ~(_fV | _fC);                                        \
  363.         if (~(A^tmp) & (A^sum) & _fN)                            \
  364.             P |= _fV;                                            \
  365.         if (sum & 0xff00)                                        \
  366.             P |= _fC;                                            \
  367.         A = (UINT8) sum;                                        \
  368.     }                                                            \
  369.     SET_NZ(A)
  370.  
  371. /* 6280 ********************************************************
  372.  *    AND Logical and
  373.  ***************************************************************/
  374. #define AND                                                     \
  375.     A = (UINT8)(A & tmp);                                        \
  376.     SET_NZ(A)
  377.  
  378. /* 6280 ********************************************************
  379.  *    ASL Arithmetic shift left
  380.  ***************************************************************/
  381. #define ASL                                                     \
  382.     P = (P & ~_fC) | ((tmp >> 7) & _fC);                        \
  383.     tmp = (UINT8)(tmp << 1);                                    \
  384.     SET_NZ(tmp)
  385.  
  386. /* 6280 ********************************************************
  387.  *  BBR Branch if bit is reset
  388.  ***************************************************************/
  389. #define BBR(bit)                                                \
  390.     BRA(!(tmp & (1<<bit)))
  391.  
  392. /* 6280 ********************************************************
  393.  *  BBS Branch if bit is set
  394.  ***************************************************************/
  395. #define BBS(bit)                                                \
  396.     BRA(tmp & (1<<bit))
  397.  
  398. /* 6280 ********************************************************
  399.  *    BCC Branch if carry clear
  400.  ***************************************************************/
  401. #define BCC BRA(!(P & _fC))
  402.  
  403. /* 6280 ********************************************************
  404.  *    BCS Branch if carry set
  405.  ***************************************************************/
  406. #define BCS BRA(P & _fC)
  407.  
  408. /* 6280 ********************************************************
  409.  *    BEQ Branch if equal
  410.  ***************************************************************/
  411. #if LAZY_FLAGS
  412. #define BEQ BRA(!(NZ & 0xff))
  413. #else
  414. #define BEQ BRA(P & _fZ)
  415. #endif
  416.  
  417. /* 6280 ********************************************************
  418.  *    BIT Bit test
  419.  ***************************************************************/
  420. #define BIT                                                        \
  421.     P = (P & ~(_fN|_fV|_fT|_fZ))                                \
  422.         | ((tmp&0x80) ? _fN:0)                                    \
  423.         | ((tmp&0x40) ? _fV:0)                                    \
  424.         | ((tmp&A)  ? 0:_fZ)
  425.  
  426. /* 6280 ********************************************************
  427.  *    BMI Branch if minus
  428.  ***************************************************************/
  429. #if LAZY_FLAGS
  430. #define BMI BRA(NZ & 0x8000)
  431. #else
  432. #define BMI BRA(P & _fN)
  433. #endif
  434.  
  435. /* 6280 ********************************************************
  436.  *    BNE Branch if not equal
  437.  ***************************************************************/
  438. #if LAZY_FLAGS
  439. #define BNE BRA(NZ & 0xff)
  440. #else
  441. #define BNE BRA(!(P & _fZ))
  442. #endif
  443.  
  444. /* 6280 ********************************************************
  445.  *    BPL Branch if plus
  446.  ***************************************************************/
  447. #if LAZY_FLAGS
  448. #define BPL BRA(!(NZ & 0x8000))
  449. #else
  450. #define BPL BRA(!(P & _fN))
  451. #endif
  452.  
  453. /* 6280 ********************************************************
  454.  *    BRK Break
  455.  *    increment PC, push PC hi, PC lo, flags (with B bit set),
  456.  *    set I flag, reset D flag and jump via IRQ vector
  457.  ***************************************************************/
  458. #define BRK                                                     \
  459.     logerror("BRK %04x\n",cpu_get_pc());    \
  460.     PCW++;                                                        \
  461.     PUSH(PCH);                                                    \
  462.     PUSH(PCL);                                                    \
  463.     PUSH(P | _fB);                                                \
  464.     P = (P & ~_fD) | _fI;                                        \
  465.     PCL = RDMEM(H6280_IRQ2_VEC);                                 \
  466.     PCH = RDMEM(H6280_IRQ2_VEC+1)
  467.  
  468. /* 6280 ********************************************************
  469.  *    BSR Branch to subroutine
  470.  ***************************************************************/
  471. #define BSR                                                     \
  472.     PUSH(PCH);                                                    \
  473.     PUSH(PCL);                                                    \
  474.     h6280_ICount -= 4; /* 4 cycles here, 4 in BRA */            \
  475.     BRA(1)
  476.  
  477. /* 6280 ********************************************************
  478.  *    BVC Branch if overflow clear
  479.  ***************************************************************/
  480. #define BVC BRA(!(P & _fV))
  481.  
  482. /* 6280 ********************************************************
  483.  *    BVS Branch if overflow set
  484.  ***************************************************************/
  485. #define BVS BRA(P & _fV)
  486.  
  487. /* 6280 ********************************************************
  488.  *  CLA Clear accumulator
  489.  ***************************************************************/
  490. #define CLA                                                     \
  491.     A = 0
  492.  
  493. /* 6280 ********************************************************
  494.  *    CLC Clear carry flag
  495.  ***************************************************************/
  496. #define CLC                                                     \
  497.     P &= ~_fC
  498.  
  499. /* 6280 ********************************************************
  500.  *    CLD Clear decimal flag
  501.  ***************************************************************/
  502. #define CLD                                                     \
  503.     P &= ~_fD
  504.  
  505. /* 6280 ********************************************************
  506.  *    CLI Clear interrupt flag
  507.  ***************************************************************/
  508. #define CLI                                                     \
  509.     if( P & _fI )                                                \
  510.     {                                                            \
  511.         P &= ~_fI;                                                \
  512.         CHECK_IRQ_LINES;                                        \
  513.     }
  514.  
  515.  
  516. /* 6280 ********************************************************
  517.  *    CLV Clear overflow flag
  518.  ***************************************************************/
  519. #define CLV                                                     \
  520.     P &= ~_fV
  521.  
  522. /* 6280 ********************************************************
  523.  *  CLX Clear index X
  524.  ***************************************************************/
  525. #define CLX                                                     \
  526.     X = 0
  527.  
  528. /* 6280 ********************************************************
  529.  *  CLY Clear index Y
  530.  ***************************************************************/
  531. #define CLY                                                     \
  532.     Y = 0
  533.  
  534. /* 6280 ********************************************************
  535.  *    CMP Compare accumulator
  536.  ***************************************************************/
  537. #define CMP                                                     \
  538.     P &= ~_fC;                                                    \
  539.     if (A >= tmp)                                                \
  540.         P |= _fC;                                                \
  541.     SET_NZ((UINT8)(A - tmp))
  542.  
  543. /* 6280 ********************************************************
  544.  *    CPX Compare index X
  545.  ***************************************************************/
  546. #define CPX                                                     \
  547.     P &= ~_fC;                                                    \
  548.     if (X >= tmp)                                                \
  549.         P |= _fC;                                                \
  550.     SET_NZ((UINT8)(X - tmp))
  551.  
  552. /* 6280 ********************************************************
  553.  *    CPY Compare index Y
  554.  ***************************************************************/
  555. #define CPY                                                     \
  556.     P &= ~_fC;                                                    \
  557.     if (Y >= tmp)                                                \
  558.         P |= _fC;                                                \
  559.     SET_NZ((UINT8)(Y - tmp))
  560.  
  561. /* 6280 ********************************************************
  562.  *  DEA Decrement accumulator
  563.  ***************************************************************/
  564. #define DEA                                                     \
  565.     A = (UINT8)--A;                                             \
  566.     SET_NZ(A)
  567.  
  568. /* 6280 ********************************************************
  569.  *    DEC Decrement memory
  570.  ***************************************************************/
  571. #define DEC                                                     \
  572.     tmp = (UINT8)--tmp;                                         \
  573.     SET_NZ(tmp)
  574.  
  575. /* 6280 ********************************************************
  576.  *    DEX Decrement index X
  577.  ***************************************************************/
  578. #define DEX                                                     \
  579.     X = (UINT8)--X;                                             \
  580.     SET_NZ(X)
  581.  
  582. /* 6280 ********************************************************
  583.  *    DEY Decrement index Y
  584.  ***************************************************************/
  585. #define DEY                                                     \
  586.     Y = (UINT8)--Y;                                             \
  587.     SET_NZ(Y)
  588.  
  589. /* 6280 ********************************************************
  590.  *    EOR Logical exclusive or
  591.  ***************************************************************/
  592. #define EOR                                                     \
  593.     A = (UINT8)(A ^ tmp);                                        \
  594.     SET_NZ(A)
  595.  
  596. /* 6280 ********************************************************
  597.  *    ILL Illegal opcode
  598.  ***************************************************************/
  599. #define ILL                                                     \
  600.     h6280_ICount -= 2; /* (assumed) */                            \
  601.     logerror("%04x: WARNING - h6280 illegal opcode\n",cpu_get_pc())
  602.  
  603. /* 6280 ********************************************************
  604.  *  INA Increment accumulator
  605.  ***************************************************************/
  606. #define INA                                                     \
  607.     A = (UINT8)++A;                                             \
  608.     SET_NZ(A)
  609.  
  610. /* 6280 ********************************************************
  611.  *    INC Increment memory
  612.  ***************************************************************/
  613. #define INC                                                     \
  614.     tmp = (UINT8)++tmp;                                         \
  615.     SET_NZ(tmp)
  616.  
  617. /* 6280 ********************************************************
  618.  *    INX Increment index X
  619.  ***************************************************************/
  620. #define INX                                                     \
  621.     X = (UINT8)++X;                                             \
  622.     SET_NZ(X)
  623.  
  624. /* 6280 ********************************************************
  625.  *    INY Increment index Y
  626.  ***************************************************************/
  627. #define INY                                                     \
  628.     Y = (UINT8)++Y;                                             \
  629.     SET_NZ(Y)
  630.  
  631. /* 6280 ********************************************************
  632.  *    JMP Jump to address
  633.  *    set PC to the effective address
  634.  ***************************************************************/
  635. #define JMP                                                     \
  636.     PCD = EAD
  637.  
  638. /* 6280 ********************************************************
  639.  *    JSR Jump to subroutine
  640.  *    decrement PC (sic!) push PC hi, push PC lo and set
  641.  *    PC to the effective address
  642.  ***************************************************************/
  643. #define JSR                                                     \
  644.     PCW--;                                                        \
  645.     PUSH(PCH);                                                    \
  646.     PUSH(PCL);                                                    \
  647.     PCD = EAD
  648.  
  649. /* 6280 ********************************************************
  650.  *    LDA Load accumulator
  651.  ***************************************************************/
  652. #define LDA                                                     \
  653.     A = (UINT8)tmp;                                             \
  654.     SET_NZ(A)
  655.  
  656. /* 6280 ********************************************************
  657.  *    LDX Load index X
  658.  ***************************************************************/
  659. #define LDX                                                     \
  660.     X = (UINT8)tmp;                                             \
  661.     SET_NZ(X)
  662.  
  663. /* 6280 ********************************************************
  664.  *    LDY Load index Y
  665.  ***************************************************************/
  666. #define LDY                                                     \
  667.     Y = (UINT8)tmp;                                             \
  668.     SET_NZ(Y)
  669.  
  670. /* 6280 ********************************************************
  671.  *    LSR Logic shift right
  672.  *    0 -> [7][6][5][4][3][2][1][0] -> C
  673.  ***************************************************************/
  674. #define LSR                                                     \
  675.     P = (P & ~_fC) | (tmp & _fC);                                \
  676.     tmp = (UINT8)tmp >> 1;                                        \
  677.     SET_NZ(tmp)
  678.  
  679. /* 6280 ********************************************************
  680.  *    NOP No operation
  681.  ***************************************************************/
  682. #define NOP
  683.  
  684. /* 6280 ********************************************************
  685.  *    ORA Logical inclusive or
  686.  ***************************************************************/
  687. #define ORA                                                     \
  688.     A = (UINT8)(A | tmp);                                        \
  689.     SET_NZ(A)
  690.  
  691. /* 6280 ********************************************************
  692.  *    PHA Push accumulator
  693.  ***************************************************************/
  694. #define PHA                                                     \
  695.     PUSH(A)
  696.  
  697. /* 6280 ********************************************************
  698.  *    PHP Push processor status (flags)
  699.  ***************************************************************/
  700. #define PHP                                                     \
  701.     COMPOSE_P(0,0);                                             \
  702.     PUSH(P)
  703.  
  704. /* 6280 ********************************************************
  705.  *  PHX Push index X
  706.  ***************************************************************/
  707. #define PHX                                                     \
  708.     PUSH(X)
  709.  
  710. /* 6280 ********************************************************
  711.  *  PHY Push index Y
  712.  ***************************************************************/
  713. #define PHY                                                     \
  714.     PUSH(Y)
  715.  
  716. /* 6280 ********************************************************
  717.  *    PLA Pull accumulator
  718.  ***************************************************************/
  719. #define PLA                                                     \
  720.     PULL(A);                                                    \
  721.     SET_NZ(A)
  722.  
  723. /* 6280 ********************************************************
  724.  *    PLP Pull processor status (flags)
  725.  ***************************************************************/
  726. #if LAZY_FLAGS
  727.  
  728. #define PLP                                                     \
  729.     PULL(P);                                                    \
  730.     NZ = ((P & _fN) << 8) |                                     \
  731.          ((P & _fZ) ^ _fZ);                                     \
  732.     CHECK_IRQ_LINES
  733.  
  734. #else
  735.  
  736. #define PLP                                                     \
  737.     PULL(P);                                                     \
  738.     CHECK_IRQ_LINES
  739. #endif
  740.  
  741. /* 6280 ********************************************************
  742.  *  PLX Pull index X
  743.  ***************************************************************/
  744. #define PLX                                                     \
  745.     PULL(X)
  746.  
  747. /* 6280 ********************************************************
  748.  *  PLY Pull index Y
  749.  ***************************************************************/
  750. #define PLY                                                     \
  751.     PULL(Y)
  752.  
  753. /* 6280 ********************************************************
  754.  *  RMB Reset memory bit
  755.  ***************************************************************/
  756. #define RMB(bit)                                                \
  757.     tmp &= ~(1<<bit)
  758.  
  759. /* 6280 ********************************************************
  760.  *    ROL Rotate left
  761.  *    new C <- [7][6][5][4][3][2][1][0] <- C
  762.  ***************************************************************/
  763. #define ROL                                                     \
  764.     tmp = (tmp << 1) | (P & _fC);                                \
  765.     P = (P & ~_fC) | ((tmp >> 8) & _fC);                        \
  766.     tmp = (UINT8)tmp;                                            \
  767.     SET_NZ(tmp)
  768.  
  769. /* 6280 ********************************************************
  770.  *    ROR Rotate right
  771.  *    C -> [7][6][5][4][3][2][1][0] -> new C
  772.  ***************************************************************/
  773. #define ROR                                                     \
  774.     tmp |= (P & _fC) << 8;                                        \
  775.     P = (P & ~_fC) | (tmp & _fC);                                \
  776.     tmp = (UINT8)(tmp >> 1);                                    \
  777.     SET_NZ(tmp)
  778.  
  779. /* 6280 ********************************************************
  780.  *    RTI Return from interrupt
  781.  *    pull flags, pull PC lo, pull PC hi and increment PC
  782.  ***************************************************************/
  783. #if LAZY_FLAGS
  784.  
  785. #define RTI                                                     \
  786.     PULL(P);                                                    \
  787.     NZ = ((P & _fN) << 8) |                                     \
  788.          ((P & _fZ) ^ _fZ);                                     \
  789.     PULL(PCL);                                                    \
  790.     PULL(PCH);                                                    \
  791.     CHECK_IRQ_LINES
  792. #else
  793.  
  794. #define RTI                                                     \
  795.     PULL(P);                                                    \
  796.     PULL(PCL);                                                    \
  797.     PULL(PCH);                                                    \
  798.     CHECK_IRQ_LINES
  799. #endif
  800.  
  801. /* 6280 ********************************************************
  802.  *    RTS Return from subroutine
  803.  *    pull PC lo, PC hi and increment PC
  804.  ***************************************************************/
  805. #define RTS                                                     \
  806.     PULL(PCL);                                                    \
  807.     PULL(PCH);                                                    \
  808.     PCW++;                                                        \
  809.  
  810. /* 6280 ********************************************************
  811.  *  SAX Swap accumulator and index X
  812.  ***************************************************************/
  813. #define SAX                                                     \
  814.     tmp = X;                                                    \
  815.     X = A;                                                      \
  816.     A = tmp
  817.  
  818. /* 6280 ********************************************************
  819.  *  SAY Swap accumulator and index Y
  820.  ***************************************************************/
  821. #define SAY                                                     \
  822.     tmp = Y;                                                    \
  823.     Y = A;                                                      \
  824.     A = tmp
  825.  
  826. /* 6280 ********************************************************
  827.  *    SBC Subtract with carry
  828.  ***************************************************************/
  829. #define SBC                                                     \
  830.     if (P & _fD)                                                \
  831.     {                                                            \
  832.     int c = (P & _fC) ^ _fC;                                    \
  833.     int sum = A - tmp - c;                                        \
  834.     int lo = (A & 0x0f) - (tmp & 0x0f) - c;                     \
  835.     int hi = (A & 0xf0) - (tmp & 0xf0);                         \
  836.         P &= ~(_fV | _fC);                                        \
  837.         if ((A^tmp) & (A^sum) & _fN)                            \
  838.             P |= _fV;                                            \
  839.         if (lo & 0xf0)                                            \
  840.             lo -= 6;                                            \
  841.         if (lo & 0x80)                                            \
  842.             hi -= 0x10;                                         \
  843.         if (hi & 0x0f00)                                        \
  844.             hi -= 0x60;                                         \
  845.         if ((sum & 0xff00) == 0)                                \
  846.             P |= _fC;                                            \
  847.         A = (lo & 0x0f) + (hi & 0xf0);                            \
  848.     }                                                            \
  849.     else                                                        \
  850.     {                                                            \
  851.     int c = (P & _fC) ^ _fC;                                    \
  852.     int sum = A - tmp - c;                                        \
  853.         P &= ~(_fV | _fC);                                        \
  854.         if ((A^tmp) & (A^sum) & _fN)                            \
  855.             P |= _fV;                                            \
  856.         if ((sum & 0xff00) == 0)                                \
  857.             P |= _fC;                                            \
  858.         A = (UINT8) sum;                                        \
  859.     }                                                            \
  860.     SET_NZ(A)
  861.  
  862. /* 6280 ********************************************************
  863.  *    SEC Set carry flag
  864.  ***************************************************************/
  865. #define SEC                                                     \
  866.     P |= _fC
  867.  
  868. /* 6280 ********************************************************
  869.  *    SED Set decimal flag
  870.  ***************************************************************/
  871. #define SED                                                     \
  872.     P |= _fD
  873.  
  874. /* 6280 ********************************************************
  875.  *    SEI Set interrupt flag
  876.  ***************************************************************/
  877. #define SEI                                                     \
  878.     P |= _fI
  879.  
  880. /* 6280 ********************************************************
  881.  *    SET Set t flag
  882.  ***************************************************************/
  883. #define SET                                                     \
  884.     P |= _fT;                                                    \
  885.     logerror("%04x: WARNING H6280 SET\n",cpu_get_pc())
  886.  
  887. /* 6280 ********************************************************
  888.  *  SMB Set memory bit
  889.  ***************************************************************/
  890. #define SMB(bit)                                                \
  891.     tmp |= (1<<bit)
  892.  
  893. /* 6280 ********************************************************
  894.  *  ST0 Store at hardware address 0
  895.  ***************************************************************/
  896. #define ST0                                                     \
  897.     cpu_writeport(0x0000,tmp)
  898.  
  899. /* 6280 ********************************************************
  900.  *  ST1 Store at hardware address 2
  901.  ***************************************************************/
  902. #define ST1                                                     \
  903.     cpu_writeport(0x0002,tmp)
  904.  
  905. /* 6280 ********************************************************
  906.  *  ST2 Store at hardware address 3
  907.  ***************************************************************/
  908. #define ST2                                                     \
  909.     cpu_writeport(0x0003,tmp)
  910.  
  911. /* 6280 ********************************************************
  912.  *    STA Store accumulator
  913.  ***************************************************************/
  914. #define STA                                                     \
  915.     tmp = A
  916.  
  917. /* 6280 ********************************************************
  918.  *    STX Store index X
  919.  ***************************************************************/
  920. #define STX                                                     \
  921.     tmp = X
  922.  
  923. /* 6280 ********************************************************
  924.  *    STY Store index Y
  925.  ***************************************************************/
  926. #define STY                                                     \
  927.     tmp = Y
  928.  
  929. /* 6280 ********************************************************
  930.  * STZ  Store zero
  931.  ***************************************************************/
  932. #define STZ                                                     \
  933.     tmp = 0
  934.  
  935. /* H6280 *******************************************************
  936.  *  SXY Swap index X and index Y
  937.  ***************************************************************/
  938. #define SXY                                                    \
  939.     tmp = X;                                                   \
  940.     X = Y;                                                     \
  941.     Y = tmp
  942.  
  943. /* H6280 *******************************************************
  944.  *  TAI
  945.  ***************************************************************/
  946. #define TAI                                                     \
  947.     from=RDMEMW(PCW);                                            \
  948.     to  =RDMEMW(PCW+2);                                            \
  949.     length=RDMEMW(PCW+4);                                        \
  950.     PCW+=6;                                                     \
  951.     alternate=0;                                                 \
  952.     while ((length--) != 0) {                                     \
  953.         WRMEM(to,RDMEM(from+alternate));                         \
  954.         to++;                                                     \
  955.         alternate ^= 1;                                         \
  956.     }                                                             \
  957.     h6280_ICount-=(6 * length) + 17;
  958.  
  959. /* H6280 *******************************************************
  960.  *  TAM Transfer accumulator to memory mapper register(s)
  961.  ***************************************************************/
  962. #define TAM                                                     \
  963.     if (tmp&0x01) h6280.mmr[0] = A;                             \
  964.     if (tmp&0x02) h6280.mmr[1] = A;                             \
  965.     if (tmp&0x04) h6280.mmr[2] = A;                             \
  966.     if (tmp&0x08) h6280.mmr[3] = A;                             \
  967.     if (tmp&0x10) h6280.mmr[4] = A;                             \
  968.     if (tmp&0x20) h6280.mmr[5] = A;                             \
  969.     if (tmp&0x40) h6280.mmr[6] = A;                             \
  970.     if (tmp&0x80) h6280.mmr[7] = A
  971.  
  972. /* 6280 ********************************************************
  973.  *    TAX Transfer accumulator to index X
  974.  ***************************************************************/
  975. #define TAX                                                     \
  976.     X = A;                                                        \
  977.     SET_NZ(X)
  978.  
  979. /* 6280 ********************************************************
  980.  *    TAY Transfer accumulator to index Y
  981.  ***************************************************************/
  982. #define TAY                                                     \
  983.     Y = A;                                                        \
  984.     SET_NZ(Y)
  985.  
  986. /* 6280 ********************************************************
  987.  *  TDD
  988.  ***************************************************************/
  989. #define TDD                                                     \
  990.     from=RDMEMW(PCW);                                            \
  991.     to  =RDMEMW(PCW+2);                                            \
  992.     length=RDMEMW(PCW+4);                                        \
  993.     PCW+=6;                                                     \
  994.     while ((length--) != 0) {                                     \
  995.         WRMEM(to,RDMEM(from));                                     \
  996.         to--;                                                     \
  997.         from--;                                                    \
  998.     }                                                             \
  999.     h6280_ICount-=(6 * length) + 17;
  1000.  
  1001. /* 6280 ********************************************************
  1002.  *  TIA
  1003.  ***************************************************************/
  1004. #define TIA                                                     \
  1005.     from=RDMEMW(PCW);                                            \
  1006.     to  =RDMEMW(PCW+2);                                            \
  1007.     length=RDMEMW(PCW+4);                                        \
  1008.     PCW+=6;                                                     \
  1009.     alternate=0;                                                 \
  1010.     while ((length--) != 0) {                                     \
  1011.         WRMEM(to+alternate,RDMEM(from));                        \
  1012.         from++;                                                 \
  1013.         alternate ^= 1;                                         \
  1014.     }                                                             \
  1015.     h6280_ICount-=(6 * length) + 17;
  1016.  
  1017. /* 6280 ********************************************************
  1018.  *  TII
  1019.  ***************************************************************/
  1020. #define TII                                                     \
  1021.     from=RDMEMW(PCW);                                            \
  1022.     to  =RDMEMW(PCW+2);                                            \
  1023.     length=RDMEMW(PCW+4);                                        \
  1024.     PCW+=6;                                                     \
  1025.     while ((length--) != 0) {                                     \
  1026.         WRMEM(to,RDMEM(from));                                     \
  1027.         to++;                                                     \
  1028.         from++;                                                    \
  1029.     }                                                             \
  1030.     h6280_ICount-=(6 * length) + 17;
  1031.  
  1032. /* 6280 ********************************************************
  1033.  *  TIN Transfer block, source increments every loop
  1034.  ***************************************************************/
  1035. #define TIN                                                     \
  1036.     from=RDMEMW(PCW);                                            \
  1037.     to  =RDMEMW(PCW+2);                                            \
  1038.     length=RDMEMW(PCW+4);                                        \
  1039.     PCW+=6;                                                     \
  1040.     while ((length--) != 0) {                                     \
  1041.         WRMEM(to,RDMEM(from));                                     \
  1042.         from++;                                                    \
  1043.     }                                                             \
  1044.     h6280_ICount-=(6 * length) + 17;
  1045.  
  1046. /* 6280 ********************************************************
  1047.  *  TMA Transfer memory mapper register(s) to accumulator
  1048.  *  the highest bit set in tmp is the one that counts
  1049.  ***************************************************************/
  1050. #define TMA                                                     \
  1051.     if (tmp&0x01) A = h6280.mmr[0];                             \
  1052.     if (tmp&0x02) A = h6280.mmr[1];                             \
  1053.     if (tmp&0x04) A = h6280.mmr[2];                             \
  1054.     if (tmp&0x08) A = h6280.mmr[3];                             \
  1055.     if (tmp&0x10) A = h6280.mmr[4];                             \
  1056.     if (tmp&0x20) A = h6280.mmr[5];                             \
  1057.     if (tmp&0x40) A = h6280.mmr[6];                             \
  1058.     if (tmp&0x80) A = h6280.mmr[7]
  1059.  
  1060. /* 6280 ********************************************************
  1061.  * TRB  Test and reset bits
  1062.  ***************************************************************/
  1063. #define TRB                                                       \
  1064.     P = (P & ~(_fN|_fV|_fT|_fZ))                                \
  1065.         | ((tmp&0x80) ? _fN:0)                                    \
  1066.         | ((tmp&0x40) ? _fV:0)                                    \
  1067.         | ((tmp&A)  ? 0:_fZ);                                    \
  1068.     tmp &= ~A
  1069.  
  1070. /* 6280 ********************************************************
  1071.  * TSB  Test and set bits
  1072.  ***************************************************************/
  1073. #define TSB                                                     \
  1074.     P = (P & ~(_fN|_fV|_fT|_fZ))                                \
  1075.         | ((tmp&0x80) ? _fN:0)                                    \
  1076.         | ((tmp&0x40) ? _fV:0)                                    \
  1077.         | ((tmp&A)  ? 0:_fZ);                                    \
  1078.     tmp |= A
  1079.  
  1080. /* 6280 ********************************************************
  1081.  *    TSX Transfer stack LSB to index X
  1082.  ***************************************************************/
  1083. #define TSX                                                     \
  1084.     X = S;                                                        \
  1085.     SET_NZ(X)
  1086.  
  1087. /* 6280 ********************************************************
  1088.  *    TST
  1089.  ***************************************************************/
  1090. #define TST                                                        \
  1091.     P = (P & ~(_fN|_fV|_fT|_fZ))                                \
  1092.         | ((tmp2&0x80) ? _fN:0)                                    \
  1093.         | ((tmp2&0x40) ? _fV:0)                                    \
  1094.         | ((tmp2&tmp)  ? 0:_fZ)
  1095.  
  1096. /* 6280 ********************************************************
  1097.  *    TXA Transfer index X to accumulator
  1098.  ***************************************************************/
  1099. #define TXA                                                     \
  1100.     A = X;                                                        \
  1101.     SET_NZ(A)
  1102.  
  1103. /* 6280 ********************************************************
  1104.  *    TXS Transfer index X to stack LSB
  1105.  *    no flags changed (sic!)
  1106.  ***************************************************************/
  1107. #define TXS                                                     \
  1108.     S = X
  1109.  
  1110. /* 6280 ********************************************************
  1111.  *    TYA Transfer index Y to accumulator
  1112.  ***************************************************************/
  1113. #define TYA                                                     \
  1114.     A = Y;                                                        \
  1115.     SET_NZ(A)
  1116.